package com.zhuss.meeting.processor;

import com.zhuss.bean.bo.meeting.apply.CreateApplyBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MeetRoomCheck;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.meeting.db.dao.ext.MeetingApplyDao;
import com.zhuss.meeting.db.entity.MeetingRoomApply;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/2/20 19:28
 */
@Component("applyCreate")
public class ApplyCreate extends AbstractProcessor<Object, CreateApplyBo> implements Processor<Object, CreateApplyBo> {

    @Autowired
    private MeetingApplyDao meetingApplyDao;

    @Override
    public Object process(CreateApplyBo bo) throws WpsException {
        MeetingRoomApply m = new MeetingRoomApply();
        m.setRoomId(bo.getRoomId());
        m.setRoomName(bo.getRoomName());
        m.setStartTime(bo.getStartTime());
        m.setEndTime(bo.getEndTime());
        m.setTheme(bo.getTheme());
        m.setPersonNum(bo.getPersonNum());
        m.setStageTables(bo.getStageTables());
        m.setStagePerson(bo.getStagePerson());
        m.setScreenSlogan(bo.getScreenSlogan());
        m.setDemand(bo.getDemand());
        m.setOther(bo.getOther());
        m.setStatus(MeetRoomCheck.待审核.key());
        m.setTel(bo.getTel());
        m.setCompanyId(bo.getCompanyId());
        m.setCompanyName(bo.getCompanyName());
        m.setArea(bo.getArea());

        m.setCreator(bo.getConcurrentUserName());
        m.setCreatorId(bo.getConcurrentUserId());
        m.setCreateTime(new Date());
        meetingApplyDao.create(m);
        return null;
    }

    @Override
    public Object log(CreateApplyBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.会务.key());
        record.setAction(LogActionEnum.会议室申请创建.key());
        record.setTargetId(param.getTargetId());
        record.setTargetName(param.getRoomName());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(CreateApplyBo createApplyBo) throws WpsException {

    }
}
